# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=zstandard
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.23.0
pkgrel=1
pkgdesc='Python bindings to the Zstandard (zstd) compression library (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://python-zstandard.readthedocs.io/'
msys2_repository_url='https://github.com/indygreg/python-zstandard/'
msys2_references=(
  'archlinux: python-zstandard'
  'purl: pkg:pypi/zstandard'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-hypothesis")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-cffi")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-python-zstandard-check-compiler-type.patch)
sha256sums=('b2d8c62d08e7255f68f7a740bae85b3c9b8e5466baa9cbf7f57f1cde0ac6bc09'
            '9b2affb073fb5f5d757701b98fa3ee87a84f90c9c58d17d06c8a4e8339041afe')

prepare() {
  cd "${_realname}-$pkgver"
  patch -p1 -i "${srcdir}/0001-python-zstandard-check-compiler-type.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
